package org.smart4j.framework.helper;

import org.smart4j.framework.ConfigConstant;
import org.smart4j.framework.util.PropsUtil;

import java.util.Properties;

/**
 * Created by Wangminze on 2016/12/11.
 * Description: 属性文件的助手类
 */
public final class ConfigHelper {

    private static final Properties CONFIG_PROPS = PropsUtil.loadProps(ConfigConstant.CONFIG_FILE);

    /**
     * author: Wangminze
     * date: 2016/12/11
     * description: 获取JDBC驱动
     * @return 驱动类名字符串
     */
    public static String getJdbcDriver(){
        return PropsUtil.getString(CONFIG_PROPS, ConfigConstant.JDBC_DRIVER, "");
    }

    /**
     * author: Wangminze
     * date: 2016/12/11
     * description: 获取 JDBC URL
     * @return URL字符串
     */
    public static String getJdbcUrl(){
        return PropsUtil.getString(CONFIG_PROPS, ConfigConstant.JDBC_URL, "");
    }

    /**
     * author: Wangminze
     * date: 2016/12/11
     * description: 获取JDBC 用户名
     * @return
     */
    public static String getJdbcUsername(){
        return PropsUtil.getString(CONFIG_PROPS, ConfigConstant.JDBC_USERNAME, "");
    }

    /**
     * author: Wangminze
     * date: 2016/12/11
     * description: 获取JDBC 密码
     * @return
     */
    public static String getJdbcPassword(){
        return PropsUtil.getString(CONFIG_PROPS, ConfigConstant.JDBC_PASSWORD, "");
    }

    /**
     * author: Wangminze
     * date: 2016/12/11
     * description: 获取应用基础包名
     * @return
     */
    public static String getAppBasePackage(){
        return PropsUtil.getString(CONFIG_PROPS, ConfigConstant.APP_BASE_PACKAGE, "");
    }

    /**
     * author: Wangminze
     * date: 2016/12/11
     * description: 获取应用JSP路径
     * @return
     */
    public static String getAppJspPath(){
        return PropsUtil.getString(CONFIG_PROPS, ConfigConstant.APP_JSP_PATH, "/WEB-INF/jsp/");
    }

    /**
     * author: Wangminze
     * date: 2017/1/7
     * description: 获取应用TLD路径
     * @return
     */
    public static String getAppTldPath() {
        return PropsUtil.getString(CONFIG_PROPS, ConfigConstant.APP_JSP_PATH, "/WEB-INF/tld/");
    }

    /**
     * author: Wangminze
     * date: 2016/12/11
     * description:获取应用静态资源路径
     * @return
     */
    public static String getAppAssetPath(){
        return PropsUtil.getString(CONFIG_PROPS, ConfigConstant.APP_ASSET_PATH, "/asset/");
    }

    /**
     * author: Wangminze
     * date: 2016/12/11
     * description:获取上传文件大小的最大值
     * @return
     */
    public static int getAppUploadLimit(){
        return PropsUtil.getInt(CONFIG_PROPS, ConfigConstant.APP_UPLOAD_LIMIT, 10);
    }

    /**
     * author: Wangminze
     * date: 2016/12/31
     * description: 获取smart.properties属性文件中的String类型的配置值
     *
     * @param propsKey 属性名
     * @return 属性值
     */
    public static String getString(String propsKey) {
        return PropsUtil.getString(CONFIG_PROPS, propsKey, null);
    }

    /**
     * author: Wangminze
     * date: 2016/12/31
     * description: 获取smart.properties属性文件中Boolean类型的配置值
     *
     * @param propsKey 属性名
     * @return 属性值
     */
    public static boolean getBoolean(String propsKey) {
        return PropsUtil.getBoolean(CONFIG_PROPS, propsKey, false);
    }


}
